$(function () {
    //获取url
    var url = localStorage.getItem("ajaxUrl");
    var pass = 1;
    var upData = {};

    //批号   获取 焦点
    $("input#goods_id").focus();

    //点击返回箭头 清除 缓存 打开 storekeeper.html
    $(".head .goBack").on("click", function () {
        window.location.href = "dailyinit.html";
    });

    //根据扫描内容 得到 编号信息
    $("#goods_id").on("keydown", function (event) {
        if (event.keyCode == "13") {
            if (pass == 0) {
                return
            }
            pass = 0;
            var val = $(this).val();
            $("#goods_id").val("");
            if (!val) {
                $alert("请扫描回倒库产品标签！");
                setTimeout(function () {
                    $("#goods_id").val("").focus();
                }, 1400);
                pass = 1;
                return;
            }//加载提示符 显示
            loading_show("搜索中...");
            //获取工单
            $.ajax({
                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                type: "post",
                url: url + '/app/init/getDividewarehouse_daily',
                data: {
                    batch: val
                },
                dataType: 'json',
                json: 'callback',
                success: function (res) {
                    pass = 1;
                    if (res.success) {
                        var data = res.result;
                        //加载提示符 隐藏
                        loading_hide();
                        $alert(data.batch + "获取成功", 800);
                        $("input.id").val(data._id);
                        $("input.batch").val(data.batch);
                        $("input.customerName").val(data.customerName);
                        $("input.inventorySpecification").val(data.inventorySpecification);
                        $("input.inventoryName").val(data.inventoryName);
                        $("input.availableLength").val(data.availableLength);
                    } else {
                        $alert(res.message);
                        $("input.id").val("");
                    }
                },
                error: function (error) {
                    pass = 1;
                    //加载提示符 隐藏
                    loading_hide();
                    console.log(error);
                    $alert(error.responseText);
                }
            });
        }
    });

    //点击 确认
    $(".foot").on("click", ".add_receive", function () {
        if (pass == 0) {
            return
        }
        pass = 0;
        //判断数据
        if (!$("input.batch").val()) {
            pass = 1;
            $alert("编号不可为空！");
            return;
        }
        //获取 信息
        var batch = $(".content .batch").val();
        loading_show("盘点中...");
        $.ajax({
            headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
            type: "post",
            url: url + '/app/init/initDividewarehouse_daily',
            data: {
                batch: batch,
            },
            dataType: "json",
            json: "callback",
            timeout: 60000,
            cache: false,
            success: function (res) {
                pass = 1;
                loading_hide();
                if (res.success) {
                    $alert($("input.batch").val() + "盘点成功");
                    $(".content input").val("");
                    setTimeout(function () {
                        $("#goods_id").val("").focus();
                    }, 1400);
                } else {
                    $alert(res.message);
                }
            },
            error: function (error) {
                pass = 1;
                if (error.status == 0) {
                    loading_hide();
                    $alert("请求超时，请重新操作！");
                } else {
                    loading_hide();
                    console.log(error);
                    $alert(error.responseText);
                }
            }
        });
    });


});

